
#include "../shaderDefs.h"
#include "../simpleShader.h"

struct VSAttrs {
    vec3 Position;
    vec3 Normal;
    vec2 TexCoords;
};

interface VSOutputs {
    vec3 pos;
    vec3 normal;
    vec2 texCoords;
};

shader SimpleVS(in vec3 Position:POSITION_SIMPLE, in vec3 Normal:NORMAL_SIMPLE, in vec2 TexCoords:TEXCOORDS_SIMPLE, out VSOutputs vsout)
{
    vec4 pos=GlobalMatrices.Camera*(LocalModel.ModelView*vec4(Position, 1.f));
    
    vsout.pos=vec3(pos);
    vsout.normal=mat3(GlobalMatrices.Camera)*(LocalModel.NormalM*Normal);
    vsout.texCoords=TexCoords;
    gl_Position=ProjectVertex(GlobalMatrices.Projection, pos);
}

sampler {
    Aniso=4;
} TexDiffuse;

shader SimpleFS(in VSOutputs fsin, out vec4 fCol:COLOR0_SIMPLE)
{
    vec3 normal=normalize(fsin.normal);
    vec4 outColor=vec4(0,0,0,1);
    outColor.rgb=Lighting(normal, fsin.pos, texture(TexDiffuse, fsin.texCoords), Material.diffuse.a);
    
    fCol=outColor;
}

program SimpleShader {
    vs(430)=SimpleVS();
    fs(430)=SimpleFS();
};
